package cn.hy.机考.part01;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @author zhaomu
 * 六、最小数字
 * 给定一个整型数组，请从该数组中选择 3 个元素组成最小数字并输出(如果数组
 * 长度小于 3，则选择数组中所有元素来组成最小数字)
 * 21,30,62,5,31
 * 21305
 * <p>
 * 5,21
 * 215
 */
public class Demo06 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] str = in.nextLine().split(",");
        if (str.length == 1) {
            System.out.println(str[0]);
        } else if (str.length == 2) {
            int num1 = Integer.parseInt(str[0] + str[1]);
            int num2 = Integer.parseInt(str[1] + str[0]);
            System.out.println(Math.min(num1, num2));
        } else {
            Arrays.sort(str, (e1, e2) -> Integer.parseInt(e1) - Integer.parseInt(e2));
            String[] minNum = Arrays.copyOf(str, 3);  // 复制数组的前三个数给另一个数组
            Arrays.sort(minNum, new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                    String c1 = o1 + o2;
                    String c2 = o2 + o1;
                    return c1.compareTo(c2);
                }
            });
            String res = "";
            for (String s : minNum) {
                res += s;
            }
            System.out.println(res);
        }
    }
}
